package org.jkuang.qstar.index.iterator;

import java.util.List;
import java.util.Set;

import org.jkuang.qstar.index.store.DataNode;

/**
 * 
 * @author jkuang 2012年11月17日
 *
 */
public class NodeFilter implements TSIterFilter<DataNode> {

	int[][][] filters;
	Container container = new Container();

	@SafeVarargs
	public NodeFilter(List<Set<Integer>>... listFilters) {
		filters = new int[listFilters.length][][];
		for (int i = 0; i < listFilters.length; i++) {
			filters[i] = toArray(listFilters[i]);
		}
	}

	private int[][] toArray(List<Set<Integer>> list) {
		int[][] array = new int[list.size()][];
		for (int i = 0; i < array.length; i++) {
			array[i] = toArray(list.get(i));
		}
		return array;
	}

	private int[] toArray(Set<Integer> set) {
		int[] array = new int[set.size()];
		int index = 0;
		for (Integer v : set) {
			array[index++] = v;
		}
		return array;
	}

	@Override
	public boolean contains(DataNode t) {
		for (int i = 0; i < filters.length; i++) {
			if (!container.contains(t, filters[i])) {
				return false;
			}
		}
		return true;
	}

}